import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { getAsyncMenus } from "../async-menus";

export default defineFakeRoute([
  {
    url: "/system/menus",
    method: "get",
    //statusCode: 404,
    response: () => {
      return {
        success: true,
        message: "操作成功",
        data: getAsyncMenus()
      };
    }
  },
  {
    url: "/system/menus",
    method: "post",
    response: ({ body }) => {
      return {
        success: true,
        message: "操作成功",
        data: {
          ...body,
          id: 999
        }
      };
    }
  },
  {
    url: "/system/menus/:id",
    method: "get",
    response: ({ params }) => {
      return {
        success: true,
        message: "操作成功",
        data: getAsyncMenus().find(item => item.id == params.id)
      };
    }
  },
  {
    url: "/system/menus/:id",
    method: "put",
    response: ({ params }) => {
      return {
        success: true,
        message: "操作成功",
        data: getAsyncMenus().find(item => item.id == params.id)
      };
    }
  },
  {
    url: "/system/menus/:id",
    method: "delete",
    statusCode: 404,
    response: () => {
      return {
        success: true,
        message: "操作成功"
      };
    }
  },
  {
    url: "/system/menus",
    method: "delete",
    response: () => {
      return {
        success: false,
        message: "禁止删除"
      };
    }
  }
]);
